﻿@{
    SiteSecurity.RequireAuthenticatedUser();
    Layout = "~/Shared/_SiteLayout.cshtml";
    Page.Title = "Associate your account with OAuth & OpenID providers";

    bool isSuccessful = false;
    string provider = null;

    if (IsPost)
    {
        provider = Request.Form["provider"];
        if (!provider.IsEmpty())
        {
            AuthWebSecurity.RequestAuthentication(provider);
            return;
        }
    }
    else
    {
        var result = AuthWebSecurity.VerifyAuthentication();
        if (result.IsSuccessful)
        {
            // string username = SiteSecurity.CurrentUserName;
            AuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId);// AuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, username);
            isSuccessful = true;
            provider = result.Provider;
        }
    }

}
<hgroup class="title">
    <h1>Associate.</h1>
    <h2>Choose a service to use to log in.</h2>
</hgroup>
@if (isSuccessful)
{
    <p class="message-success">
        You have successfully associated this account with @provider.</p>
}
else
{
    <section class="social">
        <form method="post" action="">
            <h2>Use another service to log in.</h2>
            <fieldset>
                <legend>Log in using another service</legend>
                <input type="submit" name="provider" id="facebook" value="Facebook" title="Log in using your Facebook account." />
                <input type="submit" name="provider" id="twitter" value="Twitter" title="Log in using your Twitter account." />
                <input type="submit" name="provider" id="windowsLive" value="Windows Live" title="Log in using your Windows Live account." />
            </fieldset>
        </form>
    </section>
}